package dao;

import java.util.List;

import model.Bar;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.caelum.vraptor.ioc.Component;

@Component
public class BarDAO {

	Session session; 
	 
	public BarDAO(Session session) {
		this.session = session;
	}
	
	public void remove(Bar bar){
		Transaction tx = this.session.beginTransaction();
		this.session.delete(bar);
		tx.commit();
	}
	
	public void save(Bar bar) {
		Transaction tx = this.session.beginTransaction();
		this.session.save(bar);
		tx.commit();
	}
	
	public Bar retrieve(Long id){
		Transaction tx = this.session.beginTransaction();
		Bar bar = (Bar) this.session.load(Bar.class, id);
		tx.commit();
		return bar;
	}
	
	public void update(Bar bar){
		Transaction tx = this.session.beginTransaction();
		this.session.update(bar);
		tx.commit();
	}
	
	@SuppressWarnings("unchecked")
	public List<Bar> list(){
		return this.session.createCriteria(Bar.class).list();
	}

}
